module dogre.meshmanager;

import dogre.hardwarebuffer;
import dogre.plane;
import dogre.mesh;
import std.string;
import dogre.vector3;

extern(C)
{
    void* getMeshManager();
    void* call_MeshManager_getSingletonPtr();
    void* call_createPlane(void* ptr, const(char)* name, const(char)* groupName, void* plane,
                           float width, float height, int xsegments, int ysegments, bool normals,
                           ushort numTexCoordSets, float uTile, float vTile, void* upVector,
                           HardwareBuffer.Usage vertexBufferUsage, HardwareBuffer.Usage indexBufferUsage,
                           bool vertexShadowBuffer, bool indexShadowBuffer);
}

class MeshManager
{
    static void* p;
    this()
    {
        if(p is null)
            p = getMeshManager();
        assert(p);
    }
    this(void* ptr)
    {
        p = ptr;
    }
    static MeshManager getSingleton()
    {
        if(p is null)
            p = call_MeshManager_getSingletonPtr();
        assert(p);
        return new MeshManager(p);
    }
    
    MeshPtr createPlane(string name, string groupName, Plane plane, float width, float height,
                        int xsegments = 1, int ysegments = 1, bool normals = true,
                        ushort numTexCoordSets = 1, float uTile = 1, float vTile = 1, Vector3 upVector = Vector3.UNIT_Y,
                        HardwareBuffer.Usage vertexBufferUsage = HardwareBuffer.HBU_STATIC_WRITE_ONLY,
                        HardwareBuffer.Usage indexBufferUsage = HardwareBuffer.HBU_STATIC_WRITE_ONLY,
                        bool vertexShadowBuffer = true, bool indexShadowBuffer = true)
    {
        return new MeshPtr(call_createPlane(p, toStringz(name), toStringz(groupName), plane.p,
                                            width, height, xsegments, ysegments, normals, numTexCoordSets,
                                            uTile, vTile, upVector.p, vertexBufferUsage,
                                            indexBufferUsage, vertexShadowBuffer, indexShadowBuffer));
    }
    
}